package com.weeasy.payment.controller;

import com.weeasy.core.common.Result;
import com.weeasy.payment.service.PaymentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 微信支付控制器
 * 
 * @author we-easy
 * @since 1.0.0
 */
@RestController
@RequestMapping("/payment")
@RequiredArgsConstructor
@CrossOrigin(origins = "*")
public class PaymentController {

    private final PaymentService paymentService;

    /**
     * 创建支付订单
     * 
     * @param amount 支付金额
     * @param description 订单描述
     * @return 支付订单信息
     */
    @PostMapping("/create")
    public Result<String> createPayment(@RequestParam Double amount, @RequestParam String description) {
        String orderId = paymentService.createPayment(amount, description);
        return Result.success("创建支付订单成功", orderId);
    }

    /**
     * 查询支付状态
     * 
     * @param orderId 订单ID
     * @return 支付状态
     */
    @GetMapping("/status/{orderId}")
    public Result<String> getPaymentStatus(@PathVariable String orderId) {
        String status = paymentService.getPaymentStatus(orderId);
        return Result.success("查询支付状态成功", status);
    }

    /**
     * 获取支付历史
     * 
     * @return 支付历史
     */
    @GetMapping("/history")
    public Result<String> getPaymentHistory() {
        String history = paymentService.getPaymentHistory();
        return Result.success("获取支付历史成功", history);
    }
}
